Fix potential CORRUPT HEAP problem on libraries/BLE/src/BLEDevice.cpp #7597
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
Let
BLEDevice::removePeerDevice
onlibraries/BLE/src/BLEDevice.cpp
serializable to avoid potential CORRUPT HEAP problemTests scenarios
excuse for my bad English
First of all, to recur this problem, you can try these code
In my opinion, there is no problem, but you will get CORRUPT HEAP exception just like issue #6961 and this

After debugging, I found there may have some situations that invoking this function simultaneously, such as while connecting to a not available device will invoke this function after
rc != ESP_GATT_OK
onBLEClient.cpp
andESP_GATTC_DISCONNECT_EVT
onBLEClient::gattClientEventHandler
.Invoke simultaneously may cause concurrency problem of unsafe map
m_connectedClientsMap
Therefore, my solution is to add a
mutex lock
to this function, if there is some better way to fix, please revise my PRI have tested my Pull Request on framework-arduinoespressif32 3.20004.0(the environment I use is PIO I copy the version info from
package.json
) with ESP32 and ESP32-CAM BoardRelated links
maybe related to issue #6961